const url = 'http://sports.sina.com.cn/nba/12.shtml';
const http = require('http');
const cheerio = require('cheerio');
/* http.get(url, res => {
    let html = '';
    res.on('data', chunk => {
        html += chunk;
    });
    res.on('end', () => {
        console.log('html_>', html);
        const $ = cheerio.load(html);
        $('#right a').each(function() {
            console.log($(this).attr('href'))
        })
    })
}).on('error', e => {
    console.log('get error_>', e);
}) */

httpGet(url, $ => {
    $('#right a').each(function () {
        const newUrl = $(this).attr('href');
        httpGet(newUrl, _$ => {
            console.log(_$('#artibody').text())
        })
    })
})

function httpGet(url, callback) {
    http.get(url, res => {
        let html = '';
        res.on('data', chunk => {
            html += chunk;
        });
        res.on('end', () => {
            const $ = cheerio.load(html);
            typeof callback === 'function' && callback($);
        })
    }).on('error', err => {
        console.error(err)
    })
}